import 'dart:async';

import 'package:acaleph/pages/Login_page.dart';
import 'package:flutter/material.dart';
import 'package:acaleph/widget/common_webview.dart';
import 'package:acaleph/utils/fix_url_util.dart';
import 'package:acaleph/pages/test_detail_page.dart';
import 'package:acaleph/pages/test_list_page.dart';

class RouteUtil {
  static route2Web(BuildContext context, String title, String url) {
    if (null == url) {
      return;
    }
    Navigator.of(context).push(new PageRouteBuilder(
        opaque: false,
        pageBuilder: (BuildContext context, _, __) {
          return new CommonWebView(title, FixUrlUtil.getFixUrl(url));
        },
        transitionsBuilder: (_, Animation<double> animation, __, Widget child) {
          return new FadeTransition(
            opacity: animation,
            child: new FadeTransition(
              opacity:
                  new Tween<double>(begin: 0.5, end: 1.0).animate(animation),
              child: child,
            ),
          );
        }));
  }

  static route2Detail(BuildContext context, String id) {
    if (null == id) {
      return;
    }
    Navigator.of(context).push(new PageRouteBuilder(
        opaque: false,
        pageBuilder: (BuildContext context, _, __) {
          return new TestDetailPage(id);
        },
        transitionsBuilder: (_, Animation<double> animation, __, Widget child) {
          return new FadeTransition(
            opacity: animation,
            child: new FadeTransition(
              opacity:
                  new Tween<double>(begin: 0.5, end: 1.0).animate(animation),
              child: child,
            ),
          );
        }));
  }

  static route2List(BuildContext context) {
    Navigator.of(context).push(new PageRouteBuilder(
        opaque: false,
        pageBuilder: (BuildContext context, _, __) {
          return new ListPage();
        },
        transitionsBuilder: (_, Animation<double> animation, __, Widget child) {
          return new FadeTransition(
            opacity: animation,
            child: new FadeTransition(
              opacity:
              new Tween<double>(begin: 0.5, end: 1.0).animate(animation),
              child: child,
            ),
          );
        }));
  }
  static route2Form(BuildContext context,Widget page) {
    Navigator.of(context).push(new PageRouteBuilder(
        opaque: false,
        pageBuilder: (BuildContext context, _, __) {
          return page;
        },
        transitionsBuilder: (_, Animation<double> animation, __, Widget child) {
          return new FadeTransition(
            opacity: animation,
            child: new FadeTransition(
              opacity:
              new Tween<double>(begin: 0.5, end: 1.0).animate(animation),
              child: child,
            ),
          );
        }));
  }

  static route2M(BuildContext context,Widget page) {
    Navigator.of(context).push(new MaterialPageRoute(
        builder: (BuildContext context) =>page
        )
    );
  }
  static Future<dynamic> route3M(BuildContext context,Widget page) async {
      // Navigator.push returns a Future that will complete after we call
      final result = await Navigator.push(
        context,
        new MaterialPageRoute(builder: (context) => page,
        )
      );
      return result;
  }
}

